﻿using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Media;

namespace uTrade.Controls
{
    public enum DrawObjectType
    {
        Line,
        zVLines,
        CandleLine,
        vLines
    }

    public class DrawObject
    {
        public Color Color;
        public int Thickness;
        public string Symbol;
        public string Name;

        public DrawObjectType Type;

        public double[] Vals;
        public double[] Vals1;
        public double[] Vals2;
        public double[] Vals3;
        public ConcurrentDictionary<string, double[]> Values = new ConcurrentDictionary<string, double[]>();

        public string drawItemHandler = null;
    }

    public class DrawingObject
    {
        private ConcurrentDictionary<string, DrawObject> Objects = new ConcurrentDictionary<string, DrawObject>();

        internal ConcurrentDictionary<string, DrawObject> All()
        {
            return Objects;
        }

        public void Add(List<DrawObject> lstDrawObj)
        {
            foreach (DrawObject oDrawObj in lstDrawObj)
            {
                Objects.TryAdd(oDrawObj.Name, oDrawObj);
            }
        }

        public void Clear()
        {
            Objects.Clear();
        }

        public void SetDrawItemEventHandler(string id, string handlerName)
        {
            if (Objects.ContainsKey(id))
            {
                Objects[id].drawItemHandler = handlerName;
            }
        }

        public List<TextBlock> GetFormattedText(int index = -1)
        {
            List<TextBlock> lstTittle = new List<TextBlock>();

            foreach (var dobj in Objects)
            {
                var obj = dobj.Value;
                if (index == -1)
                {
                    index = obj.Vals.Length - 1;
                }
                TextBlock textBlock = new TextBlock
                {
                    Text = obj.Name + obj.Vals[index],
                    Foreground = new SolidColorBrush(obj.Color)
                };
                lstTittle.Add(textBlock);
            }
            return lstTittle;
        }
    }
}